package com.tpc.pictool.service;


import com.tpc.pictool.utils.JDBCUtil;
import com.tpc.pictool.utils.PDFUtil;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class PDFService {
    private static final Logger log = LoggerFactory.getLogger(PDFService.class);

    public PDFService() {
    }

    public void PDFToPNG() {
        FileService fileService = new FileService();
        List<Object[]> fileNameList = fileService.getFileName();
        for(int i = 0;i<fileNameList.size();i++){
            Object[] objects = fileNameList.get(i);
            try {
                PDFUtil.pdfToImageFile(objects[1].toString(),(Integer) objects[0]);
                log.info("转换成功:{},{}", objects[0], objects[1].toString());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

//        Iterator var3 = fileNameList.iterator();
//
//        while(var3.hasNext()) {
//            Object[] objects = (Object[])var3.next();
//            String fileName = objects[1].toString();
//            Connection conn = null;
//
//            try {
//                PDFUtil.pdfToImageFile(fileName);
//                String sql = "update KmAttachment set filename=replace(filename,'.pdf','.png') where Annexid=?";
//                QueryRunner queryRunner = new QueryRunner();
//                conn = JDBCUtil.getConnection();
//                queryRunner.update(conn, sql, objects[0]);
//                log.info("转换成功:{},{}", objects[0], fileName);
//            } catch (Exception var9) {
//                var9.printStackTrace();
//            }finally {
//                if(conn!=null){
//                    try {
//                        conn.close();
//                    } catch (SQLException e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//            }
//        }

    }
}
